package com.otaku.view;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public class FastJsonViewWrap extends FastJsonJsonView{
    private static List<String> containKeys;

    static {
        containKeys = ImmutableList.of("data", "msg", "code","time");
    }

    @Override
    protected Object filterModel(Map<String, Object> model) {
        List<String> removeKeys = Lists.newArrayList();
        Map<String, Object> result = Maps.newHashMap(model);
        for (Map.Entry<String, Object> entry : model.entrySet()) {
            String key = entry.getKey();
            if (!key.contains(".") && !containKeys.contains(key)) {
                removeKeys.add(key);
            }
        }
        for (String key : removeKeys) {
            result.remove(key);
        }
        return super.filterModel(result);
    }
}
